package com.demo.controller;

import com.demo.common.Result;
import com.demo.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 快速测试控制器
 */
@RestController
@RequestMapping("/quick-test")
@CrossOrigin
public class QuickTestController {
    
    @Autowired
    private ScheduleService scheduleService;
    
    /**
     * 快速测试排课数据
     */
    @GetMapping("/schedule-data")
    public Result<String> quickTestScheduleData() {
        try {
            List<com.demo.pojo.dto.ScheduleListDTO> scheduleList = scheduleService.getScheduleList();
            
            if (scheduleList.isEmpty()) {
                return Result.success("没有排课数据，请先执行智能排课");
            }
            
            StringBuilder result = new StringBuilder();
            result.append("排课数据测试结果:\n");
            result.append("总排课数量: ").append(scheduleList.size()).append("\n\n");
            
            // 显示前3个排课的详细信息
            for (int i = 0; i < Math.min(3, scheduleList.size()); i++) {
                com.demo.pojo.dto.ScheduleListDTO dto = scheduleList.get(i);
                result.append("排课 ").append(i + 1).append(":\n");
                result.append("  课程名称: ").append(dto.getCourseName() != null ? dto.getCourseName() : "未设置").append("\n");
                result.append("  教师姓名: ").append(dto.getTeacherName() != null ? dto.getTeacherName() : "未设置").append("\n");
                result.append("  教室名称: ").append(dto.getClassroomName() != null ? dto.getClassroomName() : "未设置").append("\n");
                result.append("  班级名称: ").append(dto.getClazzName() != null ? dto.getClazzName() : "未设置").append("\n");
                result.append("  时间安排: ").append(dto.getSemester() != null ? dto.getSemester() : "未设置")
                       .append(" 第").append(dto.getWeekNo() != null ? dto.getWeekNo() : "?")
                       .append("周 星期").append(dto.getDayOfWeek() != null ? dto.getDayOfWeek() : "?")
                       .append(" 第").append(dto.getPeriodNo() != null ? dto.getPeriodNo() : "?").append("节\n");
                result.append("  状态: ").append(dto.getStatus()).append("\n");
                result.append("  优先级: ").append(dto.getPriority()).append("/5\n");
                result.append("  是否固定: ").append(dto.getIsFixed() == 1 ? "是" : "否").append("\n");
                result.append("\n");
            }
            
            return Result.success(result.toString());
            
        } catch (Exception e) {
            return Result.error("测试失败: " + e.getMessage());
        }
    }
}
























